import { BaseService } from './BaseService'
import axios from 'axios'

export class TopicService extends BaseService {
    // get
    // 获取所有专题、专题图片、专题详细页面
    // 获取所有主题
    public async getAllTopic() {
        let url = this.topicsBaseUrl
        return await axios.get(url)
    }

    // 获取主题信息
    public async getTopicInfo(topicId: string) {
        let url = this.topicsBaseUrl + '/' + topicId
        return await axios.get(url)
    }

    // 分页获取主题图片
    public async getTopicImg(topicId: string, p: number, n: number) {
        let url = this.topicsBaseUrl + '/' + topicId + '/pictures?p=' + p + '&n=' + n
        return await axios.get(url)
    }

    // post
    // 创建主题
    public async createTopic(date: any) {
        const url = this.topicsBaseUrl
        await axios
            .post(url, date)
            .then(res => {
                this.success()
            })
            .catch(err => {
                this.failed(err)
            })
    }
}
